package com.heyun.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heyun.bean.BarData;
import com.heyun.bean.HeyunOrder;
import com.heyun.bean.HeyunOrderMerchandise;
import com.heyun.bean.SeriesBar;
import com.heyun.service.HeyunOrder02Service;
/**
 * @author zll
 * @Description 订单查询部分 controller
 * @Company 
 * @date 2017年12月26日
 */
@Controller
@RequestMapping("orderManagement/OrderQuery")
public class Order02Controller {
	@Autowired
	private HeyunOrder02Service heyunOrder02Service;
	/**
	 * 
	 */
	@RequestMapping("/getBarData")
	@ResponseBody
	public BarData aaa(){
		List<String> legend = new ArrayList<String>(Arrays.asList(new String[]{"计划金额","销售金额"}));//数据分组  
		List<String> category = new ArrayList<String>(Arrays.asList(new String []{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}));//横坐标  
		List<SeriesBar> series = new ArrayList<SeriesBar>();//纵坐标  
		series.add(new SeriesBar("计划金额",   
				new ArrayList<Integer>(Arrays.asList(  
						100000000,120000000,100000000,130000000,130000000,170000000,300000000,500000000,110000000,190000000,500000000,900000000))));  
		series.add(new SeriesBar("销售金额",    
				new ArrayList<Integer>(Arrays.asList(
						130000000,150000000,180000000,730000000,330000000,570000000,100000000,500000000,210000000,390000000,700000000,800000000))));  
		
		BarData barChartData=new BarData(legend, category, series);
		return barChartData;
	}
	/**
	 * 点击查询订单详情
	 */
	@RequestMapping("/order02ToView")
	@ResponseBody
	public HeyunOrder getOrder02(String orCusId){
		int orCusIda = Integer.parseInt(orCusId);
		return heyunOrder02Service.getOrder02View(orCusIda);
	}
	/**
	 * 跳转到订单查询页面自动加载的部分
	 */
	@RequestMapping("/automaticOrder02")
	@ResponseBody
	public Map<String,Object> ListOrder(String getoption,String QueryConditions,Integer currentpage){
		HeyunOrder heyunOrder = new HeyunOrder();
		HeyunOrderMerchandise heyunOrderMerchandise = new HeyunOrderMerchandise();
		if("商品名称".equals(getoption)){
			String orMerName = QueryConditions;
			heyunOrderMerchandise.setOrMerName(orMerName);
		}else if("商品编号".equals(getoption)){
			int orMerId = Integer.parseInt(QueryConditions);
			heyunOrderMerchandise.setOrMerId(orMerId);
		}else if("订单号".equals(getoption)){
			int orCusId = Integer.parseInt(QueryConditions);
			heyunOrder.setOrCusId(orCusId);
		}else if("收货人".equals(getoption)){
			String orName = QueryConditions;
			heyunOrder.setOrName(orName);
			System.out.println(orName+"orName");
		}
		if("商品名称".equals(getoption) || "商品编号".equals(getoption)){
			System.out.println("666666666666666666666");
			//向订单商品表里查询订单ID
			List<Integer> list = heyunOrder02Service.listConditionsMerchandise02(heyunOrderMerchandise);
			Map<String,Object> map = new HashMap<>();
			Page page = PageHelper.startPage(currentpage,5);
			List<HeyunOrder> listOrder02 = heyunOrder02Service.listOrder01(list);
			int pages = page.getPages();//总页数
			for(int i=0;i<listOrder02.size();i++){
				List<HeyunOrderMerchandise> listOrderMerchandise02 = heyunOrder02Service.listOrderMerchandise02(listOrder02.get(i).getOrCusId());
				String MerchandiseName="";
				for(int j=0;j<listOrderMerchandise02.size();j++){
					MerchandiseName += listOrderMerchandise02.get(j).getOrMerName()+",";
				}
				listOrder02.get(i).setOrderMerchandises(MerchandiseName);
			}
			map.put("listOrder02", listOrder02);
			map.put("pages", pages);
			return map;
		}else if("订单号".equals(getoption)){
			System.out.println("88888888888888");
			Map<String,Object> map = new HashMap<>();
			Page page = PageHelper.startPage(currentpage,5);
			HeyunOrder listOrderaaa = heyunOrder02Service.listOrder03(heyunOrder);
			int pages = page.getPages();//总页数
			List<HeyunOrder> listOrder02 = new ArrayList<HeyunOrder>();
			List<HeyunOrderMerchandise> listOrderMerchandise02 = heyunOrder02Service.listOrderMerchandise02(listOrderaaa.getOrCusId());
			String MerchandiseName="";
			for(int j=0;j<listOrderMerchandise02.size();j++){
				MerchandiseName += listOrderMerchandise02.get(j).getOrMerName()+",";
			}
			listOrderaaa.setOrderMerchandises(MerchandiseName);
			listOrder02.add(listOrderaaa);
			map.put("listOrder02", listOrder02);
			map.put("pages", pages);
			return map;
		}else if("收货人".equals(getoption)){
			System.out.println("77777777777777777");
			Map<String,Object> map = new HashMap<>();
			Page page = PageHelper.startPage(currentpage,5);
			List<HeyunOrder> listOrder02 = heyunOrder02Service.listOrder02(heyunOrder);
			int pages = page.getPages();//总页数
			for(int i=0;i<listOrder02.size();i++){
				System.out.println(listOrder02.get(i).getEmpName()+"1111111111");
			}
			for(int i=0;i<listOrder02.size();i++){
				List<HeyunOrderMerchandise> listOrderMerchandise02 = heyunOrder02Service.listOrderMerchandise02(listOrder02.get(i).getOrCusId());
				String MerchandiseName="";
				for(int j=0;j<listOrderMerchandise02.size();j++){
					MerchandiseName += listOrderMerchandise02.get(j).getOrMerName()+",";
				}
				listOrder02.get(i).setOrderMerchandises(MerchandiseName);
			}
			map.put("listOrder02", listOrder02);
			map.put("pages", pages);
			return map;
		}else{
			Map<String,Object> map = new HashMap<>();
			Page page = PageHelper.startPage(currentpage,5);
			List<HeyunOrder> listOrder02 = heyunOrder02Service.listOrder();
			int pages = page.getPages();//总页数
			for(int i=0;i<listOrder02.size();i++){
				List<HeyunOrderMerchandise> listOrderMerchandise02 = heyunOrder02Service.listOrderMerchandise02(listOrder02.get(i).getOrCusId());
				String MerchandiseName="";
				for(int j=0;j<listOrderMerchandise02.size();j++){
					MerchandiseName += listOrderMerchandise02.get(j).getOrMerName()+",";
				}
				listOrder02.get(i).setOrderMerchandises(MerchandiseName);
			}
			map.put("listOrder02", listOrder02);
			map.put("pages", pages);
			return map;
		}
	}
}
